/**
 * 
 */
package com.rocky.project.action.report;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.rocky.project.model.family.Archive;
import com.rocky.project.model.family.Attachment;
import com.rocky.project.model.family.Family;
import com.rocky.project.model.family.Person;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRAbstractBeanDataSourceProvider;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

/**
 * @author chen
 * 供ireport测试用的数据
 */
public class TestArchiveReport extends JRAbstractBeanDataSourceProvider {
	
	private List<ArchiveVO> mainlist=new ArrayList<ArchiveVO>();
	@SuppressWarnings({ "unchecked", "deprecation" })	
	/**
	 * 模拟测试用
	 */
	private Archive mockArchive()
	{
		
		Archive archive=new Archive();
		
		Family family=new Family();
		family.setHouseholdername("户主姓名");
		family.setAddress("家庭住址");
		family.setFamilycode("邮政编码");
		Person person=new Person();
		person.setCardnumber("350100198202020202");
		person.setName("户主姓名");
		person.setBirthday(new Date(1982,2,2));
		person.setSex("2");
		person.setResidenceType("户籍类型");
		family.setHouseholder(person);
		Set persons= new HashSet();
		persons.add(new Object());
		family.setPersons(persons);
		archive.setFamily(family);
		Attachment pho=new Attachment();
		pho.setDisplayName("图纸一");
		pho.setType("2");
		pho.setRelativePath("c:\\图纸.jpg");
		pho.setSize(100L);
		pho.setName("图纸一");
		Set photoes= new HashSet();
		photoes.add(pho);
		archive.setPhotos(photoes);
		
		Attachment pic=new Attachment();
		pic.setDisplayName("照片一");
		pic.setType("1");
		pic.setRelativePath("c:\\照片2.jpg");
		pic.setSize(1000L);
		pic.setName("照片一");
		Set pics= new HashSet();
		pics.add(pic);
		
		Attachment att=new Attachment();
		att.setDisplayName("档案一");
		att.setType("3");
		att.setRelativePath("c:\\档案.jpg");
		att.setSize(1000L);
		att.setName("档案一");
		Set atts= new HashSet();
		atts.add(att);
		archive.setArchivePics(atts);
		
		archive.setPics(pics);
		archive.setAreacard("土地证号");
		archive.setAreanum("dihao");
		archive.setAutonum("shenpibiaohao");
		archive.setUseful("usefull");
		return archive;
	}

	public TestArchiveReport(Class beanClass) {
		super(beanClass);
		// TODO Auto-generated constructor stub
	}
	public TestArchiveReport() {
		super(TestArchiveReport.class);
		// TODO Auto-generated constructor stub
	}
	
	


	/* (non-Javadoc)
	 * @see net.sf.jasperreports.engine.JRDataSourceProvider#create(net.sf.jasperreports.engine.JasperReport)
	 */
	public JRDataSource create(JasperReport arg0) throws JRException {
		 /**
	        *测试数据，在使用中，不需要继承JRAbstractBeanDataSourceProvider，
	        *只需要把集合类封装到JRBeanCollectionDataSource中就可以了
	        **/
		ArchiveVO vo =new ArchiveVO();
		vo.initArchive(this.mockArchive());
		this.mainlist.add(vo);
	        /**测试数据自写*/
	       return new JRBeanCollectionDataSource(this.mainlist);

	}

	/* (non-Javadoc)
	 * @see net.sf.jasperreports.engine.JRDataSourceProvider#dispose(net.sf.jasperreports.engine.JRDataSource)
	 */
	public void dispose(JRDataSource arg0) throws JRException {
		this.mainlist=null;
	}

	public List<ArchiveVO> getMainlist() {
		return mainlist;
	}

	public void setMainlist(List<ArchiveVO> mainlist) {
		this.mainlist = mainlist;
	}

}
